package namespace;

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import java.awt.geom.*;
import java.math.*;
public class drawFunc extends JFrame
{
	public drawFunc(double tt,double NN)
	{
		setSize(1000,600);
		setTitle("First graphics ");
		double n=NN;// naturalne, tobto>=0
		double v=60.0; //0<v<60
		double t=tt;//-10<t<10
		int a=60;//naturalne, tobto>=0
		//N naturalne, tobto>=0   T
		//JFrame f= new JFrame("1gr");
		//f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		//f.setSize(1000, 600);
		Function func=new Function(n,t);
	    func.func();
	    DrawAxis axis = new DrawAxis(func.xArray(),func.yArray(),func.len());
	    //f.add(axis);
	    //f.setVisible(true);
	    add(axis);
	    JButton ebutton = new JButton("Exit");
	
	}
}
class Function      
{ double n1,t1;
Function(double n,double t){n1=n;t1=t;}
int[] xArray=new int[361];
double[] yArray=new double[361];
int k=-180;
 void func()    
 { for(int d=0;d<361;d++){
	    xArray[d]= k;k++;
		yArray[d] = 0;  	} 
      
   for(int i = 0; i < xArray.length; i++)    
  {    
      
   yArray [i] = Math.cos(t1/Math.sin(xArray[i]*3.14159265/180)*3.14159265/180) 
		   + Math.pow(n1, Math.sin(xArray[i]*3.14159265/180))
		   ;    
   System.out.println("x = " + xArray [i] + " y = " + yArray [i]+" i = " + i);    
  }    
    
 }
 int[] xArray(){
	 return xArray;
 }
 double[] yArray(){
	 return yArray;
 }
 int len(){
	 return xArray.length;}
}

class DrawAxis extends JPanel  //Побудова графіка
{   int[]xArray; double[] yArray;
int[]y1Array;
int[]x1Array;
int l;

double mn,max=0;
 double min=1000000000;
	DrawAxis(int[]x, double[] y,int length ){
		xArray=x;
		yArray=y;
		l=length;
		
		int[]y11Array=new int[l];
		y1Array=y11Array;
		int[]x11Array=new int[l];
		x1Array=x11Array;
		
	}
	public void paintComponent(Graphics g2)
	{   System.out.println("sin30" +Math.sin(30) );
	Color c=new Color(0,0,0);
	Graphics2D g=(Graphics2D)g2;
	g.setColor(c.GREEN);
	for(int i=0;i<l;i+=10){
		g.drawLine(x1Array[i],100 ,x1Array[i], 400); 
		
	}
	

	for(int i=100;i<=380;i+=20){
		g.drawLine(140,i ,860,i); 
		
	}
	g.setColor(c.black);
		g.drawLine(50, 400, 950, 400); 
		g.drawLine(500, 50, 500, 550); 
		g.drawLine(920, 405, 950, 400);
		g.drawLine(920, 395, 950, 400); 
		g.drawLine(500, 50, 495, 80); 
		g.drawLine(500, 50, 505, 80); 
		g.drawString("Y", 450, 50); 
		g.drawString("X", 950, 450);
		
		
		g.setColor(c.RED);
		
		for(int i=0;i<l;i++){
			y1Array[i]=0;
			x1Array[i]=0;
		}
		 for(int i = 0; i < l; i++)    
		  {    
		      
		   if
		   (yArray [i]<min) {min=yArray [i];}
		   if
		   (yArray [i]>max) {max=yArray [i];}
		   
		  } 
		 mn=300/(max);
		 System.out.println("max = " + (max));
		 for(int i = 0; i < l; i++)    
		  {    
		      
		   x1Array [i] = xArray[i]*2+500;  
		   System.out.println("xk = " + x1Array [i]);  
		   y1Array [i] =(int)(400-yArray [i]*mn);
		   System.out.println("yk = " + y1Array [i]);  
		  }    
	
		GeneralPath  genPath = new GeneralPath();
		genPath.moveTo(x1Array[0], y1Array[0]);
		for(int inn = 1; inn < (l-1)/2; inn++)
		{
			genPath.lineTo(x1Array[inn], y1Array[inn]);
		}
		genPath.moveTo(x1Array[(l-1)/2+1], y1Array[(l-1)/2+1]);
		for(int inn = (l-1)/2+2; inn < l; inn++)
		{
			genPath.lineTo(x1Array[inn], y1Array[inn]);
		}
		g.draw(genPath);
		g.setColor(c.black);
		
		double m=max/15;
		double kk=max;
		for(int i=100;i<=380;i+=20){
		
			g.drawString(kk+"", 355, i);kk=kk-m;
		}
		
		g.drawString("-Pi", x1Array[0], 440);	
		g.drawString("Pi", x1Array[360], 440);	
		g.drawString("0", x1Array[180]-10, 440);
		
	}
}

class Function1      //Функція  
{ double n1,t1,mn;//A B
Function1(double n,double t){n1=n;t1=t;}
double[] xArray=new double[361];
double[] yArray=new double[361];

int k=0;
 void func()    
 {mn=2*n1/360;
	 for(int d=0;d<361;d++){
	    xArray[d]= k*mn;k++;
		yArray[d] = 0;  	} 
      
   for(int i = 0; i < xArray.length; i++)    
  {    
      
   yArray [i] = 
		    Math.pow(xArray[i],Math.pow(2.718281,Math.cos(t1*3.14159265/180)))/Math.pow(n1+1,xArray[i] )
		   ;   
   System.out.println("x = " + xArray [i] + " y = " + yArray [i]+" i = " + i);    
  }    
    
 }
 double[] xArray(){
	 return xArray;
 }
 double[] yArray(){
	 return yArray;
 }
 int len(){
	 return xArray.length;}
}

class DrawAxis1 extends JPanel  //Побудова графіка
{   double[]xArray; double[] yArray;
int[]y1Array;
int[]x1Array;
int l;

double mn,mn1,max=0;
 double min=1000000000;
	DrawAxis1(double[]x, double[] y,int length ){
		xArray=x;
		yArray=y;
		l=length;
		
		int[]y11Array=new int[l];
		y1Array=y11Array;
		int[]x11Array=new int[l];
		x1Array=x11Array;
		
	}
	public void paintComponent(Graphics g2)
	{   System.out.println("sin30" +Math.sin(30) );
	Color c=new Color(0,0,0);
	Graphics2D g=(Graphics2D)g2;
	g.setColor(c.GREEN);
	for(int i=0;i<l;i+=10){
		g.drawLine(x1Array[i],100 ,x1Array[i], 400); 
		
	}
	

	for(int i=100;i<=380;i+=20){
		g.drawLine(140,i ,860,i); 
		
	}g.setColor(c.black);
		
		g.drawLine(50, 400, 950, 400); 
		g.drawLine(500-360, 50, 500-360, 550); 
		g.drawLine(920, 405, 950, 400);
		g.drawLine(920, 395, 950, 400); 
		g.drawLine(500-360, 50, 495-360, 80); 
		g.drawLine(500-360, 50, 505-360, 80); 
		g.drawString("Y", 150, 50); 
		g.drawString("X", 950, 450);
		
		
		
		g.setColor(c.RED);
		
		for(int i=0;i<l;i++){
			y1Array[i]=0;
			x1Array[i]=0;
		}
		 for(int i = 0; i < l; i++)    
		  {    
		      
		   if
		   (yArray [i]<min) {min=yArray [i];}
		   if
		   (yArray [i]>max) {max=yArray [i];}
		   
		  } 
		 if (max==0){mn=1;}else{
		 mn=300/(max);}
		 
		 System.out.println("max = " + (max));
		 for(int i = 0; i < l; i++)    
		  {    
		      
		   x1Array [i] = (int)(xArray[i]/xArray[1]*2+500-360);  
		   System.out.println("xk = " + x1Array [i]);  
		   y1Array [i] =(int)(400-yArray [i]*mn);
		   System.out.println("yk = " + y1Array [i]);  
		  }    
	
		GeneralPath  genPath = new GeneralPath();
		genPath.moveTo(x1Array[0], y1Array[0]);
		for(int inn = 1; inn < l; inn++)
		{
			
			genPath.lineTo(x1Array[inn], y1Array[inn]);
		}
		g.draw(genPath);
		g.setColor(c.black);
		
		double m=max/15;
		double kk=max;
		for(int i=100;i<=380;i+=20){
			
			g.drawString(kk+"", 500-355, i);kk=kk-m;
		}
		g.drawString(" 0", x1Array[0], 440);	
		g.drawString("2*N="+xArray[360], x1Array[360], 440);	
		
	}
}

class Function2      //Функція  
{ double v1,t1,mn;int a1;//A B
Function2(double v,double t,int a){v1=v;t1=t;a1=a;}
double[] xArray=new double[361];
double[] yArray=new double[361];

int k=-180;
 void func()    
 {mn=4.0/360.0;
	 for(int d=0;d<361;d++){
	    xArray[d]= k*mn;k++;
		yArray[d] = 0;  	} 
      
   for(int i = 0; i < xArray.length; i++)    
  {    
      
   yArray [i] = 
		    Math.cosh(t1*xArray[i])/Math.pow(2.718281,v1)+a1;    //функція
   System.out.println("xn = " + xArray [i] + " y = " + yArray [i]+" i = " + i);    
  }    
    
 }
 double[] xArray(){
	 return xArray;
 }
 double[] yArray(){
	 return yArray;
 }
 int len(){
	 return xArray.length;}
}

class DrawAxis2 extends JPanel  //Побудова графіка
{   double[]xArray; double[] yArray;
int[]y1Array;
int[]x1Array;
int l;

double mn,mn1,max=0;
 double min=1000000000;
	DrawAxis2(double[]x, double[] y,int length ){
		xArray=x;
		yArray=y;
		l=length;
		
		int[]y11Array=new int[l];
		y1Array=y11Array;
		int[]x11Array=new int[l];
		x1Array=x11Array;
		
	}
	public void paintComponent(Graphics g2)
	{   System.out.println("sin30" +Math.sin(30) );
	Color c=new Color(0,0,0);
		Graphics2D g=(Graphics2D)g2;
		g.setColor(c.GREEN);
		for(int i=0;i<l;i+=10){
			g.drawLine(x1Array[i],100 ,x1Array[i], 400); 
			
		}
		
	
		for(int i=100;i<=380;i+=20){
			g.drawLine(140,i ,860,i); 
			
		}
		g.setColor(c.black);
		g.drawLine(50, 400, 950, 400); 
		g.drawLine(500, 50, 500, 550); 
		g.drawLine(920, 405, 950, 400);
		g.drawLine(920, 395, 950, 400); 
		g.drawLine(500, 50, 495, 80); 
		g.drawLine(500, 50, 505, 80); 
		g.drawString("Y", 510, 50); 
		g.drawString("X", 950, 450);
		// Draw a curve;
		
		
		
		for(int i=0;i<l;i++){
			y1Array[i]=0;
			x1Array[i]=0;
		}
		 for(int i = 0; i < l; i++)    
		  {    
		      
		   if
		   (yArray [i]<min) {min=yArray [i];}
		   if
		   (yArray [i]>max) {max=yArray [i];}
		   
		  } 
		 if (max==0){mn=1;}else{
		 mn=300/(max);}
		 
		 System.out.println("mm = " + (max));
		 for(int i = 0; i < l; i++)    
		  {    
		      
		   x1Array [i] = (int)(xArray[i]/xArray[181]*2+500);  
		   System.out.println("xk = " + x1Array [i]);  
		   y1Array [i] =(int)(400-yArray [i]*mn);
		   System.out.println("yk = " + y1Array [i]);  
		  }    
		 
			g.setColor(c.RED);
		GeneralPath  genPath = new GeneralPath();
		genPath.moveTo(x1Array[0], y1Array[0]);
		for(int inn = 1; inn < l; inn++)
		{
			
			genPath.lineTo(x1Array[inn], y1Array[inn]);
		}
		g.draw(genPath);
		g.setColor(c.black);
		
			
		
		double m=max/15;
		double kk=max;
		for(int i=100;i<=380;i+=20){
			
			g.drawString(kk+"", 500+5, i);kk=kk-m;
		}
		g.drawString(""+xArray[0], x1Array[0]-10, 440);	
		g.drawString(" "+xArray[360], x1Array[360], 440);	
		
		
	}
}